package com.chengqs.rainbow.im.security.code.generator;

import com.chengqs.rainbow.im.security.code.CaptchaCode;
import com.chengqs.rainbow.im.security.code.Code;
import com.chengqs.rainbow.im.security.properties.SecurityProperties;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.awt.image.BufferedImage;

/**
 * <B>主类名称：</B>CaptchaCodeGenerator<BR>
 * <B>概要说明：</B>enter<BR>
 *
 * @author: chengqs
 * @create: 2025-09-15 21:13:22
 **/
@Component
public class CaptchaCodeGenerator implements CodeGenerator {

    @Resource
    private DefaultKaptcha defaultKaptcha;

    @Resource
    private SecurityProperties securityProperties;

    @Override
    public Code generate() {
        String code = defaultKaptcha.createText();
        BufferedImage image = defaultKaptcha.createImage(code);
        return new CaptchaCode(code, securityProperties.getCode().getCaptcha().getExpiresIn(), image);
    }
}
